<?php

namespace App\Console\Commands;
use Illuminate\Console\Command;

class marketSendUserDiamond extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'marketSendUserDiamond';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '营销业务给长期未登录的用户发送钻石';
    protected $errorLog = 'error_adminsend_diamond';//后台发送钻石失败记录
    protected $log = 'adminsend_diamond';//脚本发送钻石记录
    protected $apiservice;//调用api服务
    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $fiveUserIds = [
            '19301','18135','14919','19526','17113','13144','20175','16599',
            '15673','10361','13309','19430','11362','19240','10059','11736',
            '14203','13294','10074'
        ];
        $tenUserIds = [
            '14567','15026','10043','11217','13158','11518','10436','12843',
            '13399','16219','14840','14123','16288','13535'
        ];
        //500钻石发送
        foreach($fiveUserIds as $v)
        {
            try{
                $requestData = [
                    'user_id' => $v,
                    'type' => 4,//4.后台钻石-加减
                    'amount' => 500,
                    'description' => '后台赠送钻石500钻',
                ];
                $res = curl_request(getKkaudioApiUrl() . '/activity/increase', $requestData, 'urlencoded', 'POST');
                $res = json_decode($res, true);
                write_log($this->log,'INFO 发放500钻用户:'.$v.'状态',$res);
            }catch (\Exception $e) {
                write_log($this->errorLog,'FAIL 发放500钻石失败用户:',$v);
            }
        }
        //1000钻石发送
        foreach($tenUserIds as $v)
        {
            try{
                $requestData = [
                    'user_id' => $v,
                    'type' => 4,//4.后台钻石-加减
                    'amount' => 1000,
                    'description' => '后台赠送钻石1000钻',
                ];
                $res = curl_request(getKkaudioApiUrl(). '/activity/increase', $requestData, 'urlencoded', 'POST');
                $res = json_decode($res, true);
                write_log($this->log,'INFO 发放500钻用户:'.$v.'状态',$res);
            }catch (\Exception $e) {
                write_log($this->errorLog,'FAIL 发放1000钻石失败用户:',$v);
            }
            
        }
    }
}
